home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 June / Macworld (1999-06).dmg / Shareware World / Info / For Developers / McSerialnumber 1.2 / CSerialnumLib.h next >
Text File  |  1999-03-21  |  8KB  |  208 lines

  1. //----------------------------------------------------------------------------
  2. //    Filename:    CSerialnumLib.h
  3. //    Copyright © 1998 Wilfried Bernard. All rights reserved.
  4. //
  5. //  See the file "McSerialNumber README" for more details and the licensing 
  6. //    agreement, etc.  
  7. //
  8. //    Description:    Header to implement encoding/decoding of serial numbers
  9. //
  10. //    ATTENTION!
  11. //     ----------
  12. //     If you incorporate the 68k-library in your application
  13. //     allways use the following switches with the Metrowerks IDE:
  14. //     68k Processor:     check 4 Byte Ints and 8 Byte Doubles ON
  15. //                    check Far Data, Far Method Table and Far String Consts ON
  16. //
  17. //     INTEL - Win95/98/NT USER
  18. //    ------------------------------
  19. //     You have to convert all input strings from ANSI-C-STRINGS to PASCAL-STRINGS
  20. //     first BEFORE using CalcNameCode and StripSerialNumber!!
  21. //     You can use the included converter functions c2pstr or p2cstr
  22. //    Both functions are defined global!
  23. //
  24. //
  25. //    for questions and comments pls. contact:
  26. //    <e-mail>         mcwareusa@aol.com or mcwareusa@kagi.com
  27. //    <www-page>        http://members.aol.com/mcwareusa
  28. //
  29. //----------------------------------------------------------------------------
  30. // Revision History:
  31. // Nov, 08 1998 - 1.1.1    String converters defined global for external use - now documented
  32. // Oct, 07 1998 - 1.1     Intel types conversion added
  33. // Dec, 30 1997 - 1.0     oSWSt first public release
  34. //----------------------------------------------------------------------------
  35.  
  36.  
  37. #pragma once
  38.  
  39.  
  40. #if __INTEL__                // use for Metrowerks compiler (CW 9 & newer) ONLY!!!
  41. #ifndef _INTELTYPES
  42.     typedef unsigned char                    Boolean;
  43.     typedef unsigned char *                    StringPtr;
  44.     typedef const unsigned char *            ConstStr31Param;    // pascal string
  45.     typedef    const unsigned char *            ConstStr63Param;
  46. #endif
  47. #else
  48. #ifndef __CONDITIONALMACROS__
  49. #include <ConditionalMacros.h>
  50. #endif
  51.  
  52. #if TARGET_OS_MAC
  53. #ifndef __MACTYPES__
  54. #include <MacTypes.h>
  55. #endif
  56. #endif
  57. #endif
  58.  
  59. class CSerialnumberLib
  60. {
  61.     public:
  62.     // all Public Functions
  63.     
  64. // MANIPULATOR
  65. //----------------------------------------------------------------------------
  66. //    PARAMETER:    ConstStr31Param first_name    ATTENTION: NEEDS to be a PASACAL STRING
  67. //                ConstStr31Param last_name    ATTENTION: NEEDS to be a PASACAL STRING
  68. //            
  69. //    RESULT:        long long        test_number
  70. //    
  71. //    entering the customer first and a last name creates a 64 bit test number
  72. //    which is NOT the real serial number. 
  73. //    check with the real serialnumber AND your master code with CheckSumTest()
  74. //----------------------------------------------------------------------------
  75.     static    long long    CalcNameCode        (ConstStr31Param    inFirstNameStr,    
  76.                                              ConstStr63Param    inLastNameStr);
  77.  
  78.  
  79. //----------------------------------------------------------------------------
  80. //    PARAMETER:    long long        test_number
  81. //                long long        serial_number
  82. //                long long        master_key
  83. //            
  84. //    RESULT:        Boolean            test_valid
  85. //    
  86. //    checks validity of the real serialnumber by testing against your master code
  87. //    and the names test number (CalcNameCode)
  88. //----------------------------------------------------------------------------
  89.     static    Boolean        CheckSumTest        (long long             inNameCode, 
  90.                                              long long             inSerialNumber, 
  91.                                              long long             inMasterKey );
  92.     
  93.     
  94. //----------------------------------------------------------------------------
  95. //    PARAMETER:    ConstStr31Param    serial_number_string    ATTENTION: NEEDS to be a PASACAL STRING
  96. //                long long        serial_number
  97. //            
  98. //    RESULT:        Boolean            test_valid
  99. //    
  100. //    converts the serial number string into the real serialnumber,
  101. //    strips all non-hexadecimal characters. Reports FALSE if serialnumber
  102. //    string is invalid else TRUE
  103. //----------------------------------------------------------------------------
  104.     static    Boolean        StripSerialNumber    (ConstStr31Param    inSerNrString,    
  105.                                              long long&            outSum);
  106.  
  107. // COVERTER                          
  108. //----------------------------------------------------------------------------
  109. //    PARAMETER:    IN:        StringPtr        serial_number_string (p-string)
  110. //                OUT:    long long        serial_number
  111. //            
  112. //    RESULT:        none
  113. //    
  114. //    converts the serial number pascal-string into the 64 bit number,
  115. //----------------------------------------------------------------------------
  116.     static    void        PStrToLLong            (StringPtr            inPStr,            
  117.                                              long long&            outSum);
  118.                                              
  119. //----------------------------------------------------------------------------
  120. //    PARAMETER:    IN:        StringPtr        serial_number_string (c-string)
  121. //                OUT:    long long        serial_number
  122. //            
  123. //    RESULT:        none
  124. //    
  125. //    converts the serial number c-string into the 64 bit number,
  126. //----------------------------------------------------------------------------
  127.     static    void        ANSIStrToLLong        (char*                 inCStr,         
  128.                                              long long&            outVal);
  129.  
  130.                                              
  131. //----------------------------------------------------------------------------
  132. //    PARAMETER:    OUT:     ConstStr31Param    serial_number_string    (allocate memory!)
  133. //                IN:        long long        IN serial_number
  134. //            
  135. //    RESULT:        none
  136. //    
  137. //    converts 64 bit number into a serial number pascal-string
  138. //----------------------------------------------------------------------------
  139.     static    void        LLongToPStr            (ConstStr31Param    outPStr,        
  140.                                              long long            inSum);
  141.                                              
  142. //----------------------------------------------------------------------------
  143. //    PARAMETER:    OUT:    ConstStr31Param    serial_number_string    (allocate memory!)
  144. //                IN:        long long        serial_number
  145. //            
  146. //    RESULT:    none
  147. //    
  148. //    converts 64 bit number into a serial number pascal-string
  149. //----------------------------------------------------------------------------
  150.     static    void        LLongToANSIStr        (ConstStr31Param    outCStr,
  151.                                              long long             inVal);
  152.  
  153. //----------------------------------------------------------------------------
  154. //    INPUT:    long long        IN master_key_number (if you pass <nil> an internal 
  155. //                                                  check will take place)
  156. //            
  157. //    RESULT:    long long        OUT master_code
  158. //    
  159. //    gets the real master code number from the library
  160. //
  161. //    ATTENTION
  162. //    first set your master code as default in the McSerialnumber application
  163. //    preferences dialog BEFORE you create the library otherwise the resulting
  164. //    mastercode can be zero
  165. //----------------------------------------------------------------------------
  166.     static    long long    GetMasterCode        (long long             inMasterKey);
  167.     
  168. };
  169.  
  170. #if __INTEL__
  171. //----------------------------------------------------------------------------
  172. //    PARAMETER:    IN:        StringPtr                     PASCAL String 
  173. //                OUT:     StringPtr                    ASNI-String (allocate memory!)
  174. //                
  175. //            
  176. //    RESULT:    none
  177. //    
  178. //    converts a PASCAL string to a ANSI string in place
  179. //
  180. //----------------------------------------------------------------------------
  181. void    p2cstr(StringPtr temP);
  182.  
  183.  
  184. //----------------------------------------------------------------------------
  185. //    PARAMETER:    IN:        char*                         ASNI-String 
  186. //                OUT:     char*                        PASCAL String(allocate memory!)
  187. //                
  188. //            
  189. //    RESULT:    none
  190. //    
  191. //    converts a ANSI string to a PASCAL string in place
  192. //
  193. //----------------------------------------------------------------------------
  194. void    c2pstr(char* temP);
  195. #endif
  196.  
  197. // ATTENTION!
  198. // ----------
  199. // If you incorporate the library in your 68k Application
  200. // allways use the following switches with your Metrowerks IDE:
  201. // 68k Processor:     check 4 Byte Ints and 8 Byte Doubles ON
  202. //                    check Far Data, Far Method Table and Far String Consts ON
  203.  
  204. // INTEL Windows (95/98/NT) USER
  205. //------------------------------
  206. // you have to convert all input strings from ANSI-C-STRINGS to PASCAL-STRINGS
  207. // first before using the func. CalcNameCode and StripSerialNumber!!
  208. // you can use the included converter functions c2pstr